#ifndef __MYSQLCONF_H__
#define __MYSQLCONF_H__

#include <string>

#include "config.h"

class MysqlConf
{
public:
    const std::string GetHost() const
    {
        return m_host;
    }

    void SetHost(const std::string& host)
    {
        m_host = host;
    }

    const std::string GetUser() const
    {
        return m_user;
    }

    void SetUser(const std::string& user)
    {
        m_user = user;
    }

    const std::string GetPWD() const
    {
        return m_pwd;
    }

    void SetPWD(const std::string pwd)
    {
        m_pwd = pwd;
    }

    const std::string GetDBName() const
    {
        return m_db_name;
    }

    void SetDBName(const std::string& db_name)
    {
        m_db_name = db_name;
    }
private:
    std::string m_host;
    std::string m_user;
    std::string m_pwd;
    std::string m_db_name;
};


template<>
class LexicalCast<std::string, MysqlConf>
{
public:
    MysqlConf operator()(const std::string& str)
    {
        YAML::Node node = YAML::Load(str);
        MysqlConf mysqlConf;
        mysqlConf.SetHost(node["host"].as<std::string>());
        mysqlConf.SetUser(node["user"].as<std::string>());
        mysqlConf.SetPWD(node["pwd"].as<std::string>());
        mysqlConf.SetDBName(node["dbname"].as<std::string>());
        return mysqlConf;
    }
};

template<>
class LexicalCast<MysqlConf, std::string>
{
public:
    std::string operator()(const MysqlConf& mysqlConf)
    {
        YAML::Node node;
        std::stringstream ss;
        node["host"] = mysqlConf.GetHost();
        node["user"] = mysqlConf.GetUser();
        node["pwd"] = mysqlConf.GetPWD();
        node["dbname"] = mysqlConf.GetDBName();
        ss << node;
        return ss.str();
    }
};

#endif // !__MYSQLCONF_H__
